From 0cbfb678e21f8bfbe47887f206a27675ac51df95 Mon Sep 17 00:00:00 2001 From: Ashe Connor Date: Wed, 18 Oct 2017 17:39:11 +1100 Subject: [PATCH] Let's not accept both, just to be safe --- src/bin/install.rs | 8 ++++++-- tests/install.rs | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bin/install.rs b/src/bin/install.rs index 27b63e197..2d3a135a4 100644 --- a/src/bin/install.rs +++ b/src/bin/install.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::core::{SourceId, GitReference}; -use cargo::util::{CliResult, Config, ToUrl}; +use cargo::util::{CargoError, CliResult, Config, ToUrl}; #[derive(Deserialize)] pub struct Options { @@ -153,7 +153,11 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { }; let krates = options.arg_crate.iter().map(|s| &s[..]).collect::>(); - let vers = options.flag_version.as_ref().or(options.flag_vers.as_ref()).map(|s| &s[..]); + let vers = match (&options.flag_vers, &options.flag_version) { + (&Some(_), &Some(_)) => return Err(CargoError::from("Invalid arguments.").into()), + (&Some(ref v), _) | (_, &Some(ref v)) => Some(v.as_ref()), + _ => None, + }; let root = options.flag_root.as_ref().map(|s| &s[..]); if options.flag_list { diff --git a/tests/install.rs b/tests/install.rs index c98d4e1ae..da9181f42 100644 --- a/tests/install.rs +++ b/tests/install.rs @@ -933,13 +933,13 @@ fn version_too() { } #[test] -fn version_preferred() { +fn not_both_vers_and_version() { pkg("foo", "0.1.1"); pkg("foo", "0.1.2"); assert_that(cargo_process("install").arg("foo").arg("--version").arg("0.1.1").arg("--vers").arg("0.1.2"), - execs().with_status(0).with_stderr_contains("\ - [DOWNLOADING] foo v0.1.1 (registry [..]) + execs().with_status(101).with_stderr_contains("\ +error: Invalid arguments. ")); } -- 2.30.2